#!/usr/bin/env python
# encoding: utf-8
'''
@author: 王震
@license: 四川凡狼科技有限公司
@contact: 2668985108@qq.com
@file: curriculum.py
@time: 2021/9/29 9:53 上午
@desc:
'''

from flask import Blueprint, request
from app.business.curriculum.curriculum import create_curriculum, get_curriculum as get_list, \
    update_curriculum as update, delete_curriculum as delete, get_show_data, get_customer
from app.public.sqlMethods import auto
from app.public.sqlMethods import set_content_type
from app.msg.resp import response_json
from app.msg.tips import *

curriculum = Blueprint('curriculum', __name__, url_prefix='/api')

'''
创建课程
'''


@curriculum.route('/add/curriculum', methods=['POST'])
@auto.login_required
def add_curriculum():
    _json = request.json
    if set_content_type():
        return response_json(code=tips['content_Type'], msg=tipsText['content_Type'])
    return create_curriculum(_json=_json)


'''
获取课程列表
'''


@curriculum.route('/get/curriculum', methods=['GET'])
@auto.login_required
def get_curriculum():
    page_number = request.args.get('pageNumber', 1)
    page_size = request.args.get('pageSize', 10)
    return get_list(page_number=page_number, page_size=page_size)


'''
获取线上线下课程列表 默认显示线上课程
'''


@curriculum.route('/get/show/list', methods=['GET'])
@auto.login_required
def get_show_list():
    page_number = request.args.get('pageNumber', 1)
    page_size = request.args.get('pageSize', 10)
    show = request.args.get('show', 1)
    return get_show_data(page_number=page_number, page_size=page_size, show=show)


'''
修改课程
'''


@curriculum.route('/update/curriculum', methods=['PUT'])
@auto.login_required
def update_curriculum():
    data = request.json
    if set_content_type():
        return response_json(code=tips['content_Type'], msg=tipsText['content_Type'])
    return update(data=data)


'''
删除课程列表
'''


@curriculum.route('/delete/curriculum', methods=['DELETE'])
@auto.login_required
def delete_curriculum():
    data = request.json
    _id = data['id'] if 'id' in data else None
    if set_content_type():
        return response_json(code=tips['content_Type'], msg=tipsText['content_Type'])
    return delete(_id=_id)


'''
获取客户段列表
'''


@curriculum.route('/customer/class/list')
def _class():
    page_number = request.args.get('pageNumber', 1)
    page_size = request.args.get('pageSize', 10)
    return get_customer(page_number=page_number, page_size=page_size)
